package fg.sprite;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.opengl.renderer.Renderer;
import org.newdawn.slick.opengl.renderer.SGL;

/**
 * A SpriteGroup has a parent Sprite and child sprites. Child Sprites are
 * rendered relative to their parent's position.
 * 
 * @author robin
 * 
 */
public class SpriteGroup {

	protected List<Sprite> childs;
	protected Sprite parent;

	public SpriteGroup() {
		childs = new ArrayList<Sprite>();
	}

	public void setParent(Sprite sprite) {
		this.parent = sprite;
	}

	public void add(Sprite sprite) {
		childs.add(sprite);
	}

	public void remove(Sprite sprite) {
		childs.remove(sprite);
	}

	/**
	 * Renders the parent Sprite with it childs.
	 * 
	 * @param g
	 */
	public void render(Graphics g) {
		SGL GL = Renderer.get();
		parent.render(g);
		GL.glTranslatef(parent.x, parent.y, 0f);
		for (Sprite s : childs) {
			s.render(g);
		}
		GL.glTranslatef(-parent.x, -parent.y, 0f);
	}

}
